home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / map1addonsamendmenu.py < prev    next >
Text File  |  2004-01-05  |  33KB  |  901 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Amending functions of QuArK Map editor's "Addons" menu
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/map1addonsamendmenu.py,v 1.2 2003/12/18 21:51:46 peter-b Exp $
  12.  
  13. Info = {
  14.    "plug-in":       "Map1 Addons Amend Menu",
  15.    "desc":          "This implements the Addons menu and Categories for adding and removing 3rd party programs.",
  16.    "date":          "June 7 2003",
  17.    "author":        "cdunde, Decker and others",
  18.    "author e-mail": "cdunde1@attbi.com",
  19.    "quark":         "Version 6.4" }
  20.  
  21.  
  22. from quarkpy.maputils import *
  23. import quarkpy.qmacro
  24.  
  25. # ****************** Add Menu Items Dialog ******************
  26.  
  27.  
  28. class AddonsDlg (quarkpy.qmacro .dialogbox):
  29.     #
  30.     # dialog layout
  31.     #
  32.  
  33.     endcolor = AQUA
  34.     size = (300,155)
  35.     dfsep = 0.35
  36.     flags = FWF_KEEPFOCUS
  37.     
  38.     dlgdef = """
  39.         {
  40.         Style = "9"
  41.         Caption = "Add Item Dialog"
  42.  
  43.         catagory: =
  44.         {
  45.         Typ = "C" Txt = "select catagory:"
  46.             items =
  47.                 "Shape programs" $0D
  48.                 "Terrain programs" $0D
  49.                 "Other programs" $0D
  50.             values =
  51.                 "1" $0D
  52.                 "2" $0D
  53.                 "3" $0D
  54.         Hint = "Select a catagory of the Addons menu"$0D
  55.                "to place the program menu item in."
  56.         }
  57.  
  58.         program: =
  59.         {
  60.         Txt = "select program:"
  61.         Typ = "EP"
  62.         DefExt = "exe"
  63.         BasePath = "C:"
  64.         Hint = "Type in the full path and name of the program"$0D
  65.                "you wish to add to this menu as a menu item"$0D
  66.                "or just use the file browser ... to the right."$0D
  67.         }
  68.  
  69.         mapfile: =
  70.         {
  71.         Txt = "select mapfile:"
  72.         Typ = "EP"
  73.         DefExt = "map"
  74.         BasePath = "$Game\\tmpQuArK\maps"
  75.         Hint = "Type in the full path and name of an optional"$0D
  76.                "mapfile you wish to use for the programs output"$0D
  77.                "or just use the file browser ... to the right."$0D
  78.         }
  79.  
  80.         sep: = { Typ="S" Txt=" " }
  81.  
  82.         close:py = {Txt="" }
  83.         cancel:py = {Txt="" }
  84.  
  85.     }
  86.     """
  87.  
  88.     #
  89.     # __init__ initialize the object
  90.     #
  91.  
  92.     def __init__(self, form, editor, action):
  93.  
  94.     #
  95.     # General initialization of some local values
  96.     #
  97.  
  98.         self.editor = editor
  99.         src = quarkx.newobj(":")
  100.         self.src = src
  101.         self.action = action
  102.         self.form = form
  103.         self.src["program"] = None
  104.         self.src["mapfile"] = quarkx.outputfile("maps\\1SaveImport.map")
  105.  
  106.     #
  107.     # Create the dialog form and the buttons
  108.     #
  109.  
  110.         quarkpy.qmacro.dialogbox.__init__(self, form, src,
  111.         close = quarkpy.qtoolbar.button(
  112.             self.close,
  113.             "Add the selected program",
  114.             ico_editor, 3,
  115.             "Reload"),
  116.         cancel = quarkpy.qtoolbar.button(
  117.             self.cancel,
  118.             "Cancel & close window",
  119.             ico_editor, 0,
  120.             "Cancel"))
  121.  
  122.     def onclose(self, dlg):
  123.         if self.src is None:
  124.             qmacro.dialogbox.onclose(self, dlg)
  125.             return
  126.         quarkx.globalaccept()
  127.         self.action(self)
  128.         qmacro.dialogbox.onclose(self, dlg)
  129.  
  130.     def cancel(self, dlg):
  131.         self.src = None 
  132.         qmacro.dialogbox.close(self, dlg)
  133.  
  134.  
  135. #        ********** Addons FUNCTION Starts Here **********
  136.  
  137.  
  138. def CreateMenuItems(self):
  139.  
  140.     catagory = self.src["catagory"]
  141.     if catagory == "1":
  142.         catagory = "ShapesMenu"
  143.     if catagory == "2":
  144.         catagory = "TerrainMenu"
  145.     if catagory == "3":
  146.         catagory = "OtherMenu"
  147.     program = self.src["program"]
  148.     words = program.split("\\")
  149.     cmdline = words [-1]
  150.     path_to_program = words [ 0 : -1 ]
  151.     currentdir = "\\".join(path_to_program)
  152.     words = ".".split(cmdline)
  153.     name =  words [0]
  154.     name = name.replace(" ", "")
  155.     mapfile = self.src["mapfile"]
  156.     objfile = mapfile.replace("\\", "/")
  157.     proglocate = program.replace("\\", "/")
  158.  
  159.  
  160.     outfile = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py", "w")
  161.  
  162.     outfile.write("Info = {\n\n   'plug-in':       'Addons Menu Edit',")
  163.  
  164.     outfile.write("\n\n   'desc':          'This file stores the Addons Main menu, Category sub-menu items. It is created by the plugins map1addonsamendmenu.py file.',")
  165.  
  166.     outfile.write("\n\n   'date':          'June 7 2003',")
  167.  
  168.     outfile.write("\n\n   'author':        'cdunde, Decker and others',")
  169.  
  170.     outfile.write("\n\n   'author e-mail': 'cdunde1@attbi.com',")
  171.  
  172.     outfile.write("\n\n   'quark':         'Version 6.4' }\n\n")
  173.  
  174.     outfile.write("# Deleting this file well remove all items\n# added to the Addons Menu Categories.\n\n")
  175.  
  176.     outfile.write("from quarkpy.maputils import *\nimport quarkpy.mapeditor\nimport quarkpy.qmenu\nimport map1addonsmenu\n\n")
  177.  
  178.     outfile.write("# ================DO NOT DELETE ABOVE THIS LINE =================\n\n")
  179.  
  180. # New test line
  181.     outfile.write("#===========================================\n\n")
  182.  
  183.     outfile.write("plugins.map1addonsmenu."+catagory+".items.append(qmenu.sep)\n\n")
  184.  
  185.     outfile.write("# ------------ Delete This Item ------------\n\n")
  186.  
  187.     outfile.write("# Menu Catagory: "+catagory+"\n")
  188.  
  189.     outfile.write("# Menu Title: Run "+name+"\n\n")
  190.  
  191.     outfile.write("def Run_"+name+"(self):\n    pass\n    cmdline = '"+cmdline+"'\n    currentdir = '"+currentdir+"'\n    quarkx.runprogram(cmdline, currentdir)\n\n")
  192.  
  193.     outfile.write("plugins.map1addonsmenu."+catagory+".items.append(quarkpy.qmenu.item('Run "+name+"', Run_"+name+",'|This programs location is:\\n\\n"+proglocate+"'))\n\n")
  194.  
  195.     outfile.write("# ------------ End Item Cutting ------------\n\n")
  196.  
  197.     outfile.write("# ------------ Delete This Item ------------\n\n")
  198.  
  199.     outfile.write("# Menu Catagory: "+catagory+"\n")
  200.  
  201.     outfile.write("# Menu Title: Import "+name+" map\n\n")
  202.  
  203.     outfile.write("def Load_"+name+"_Map(editor):\n    pass\n    editor = mapeditor()\n    info = quarkx.openfileobj('"+objfile+"')\n    mygroup = quarkx.newobj('group:g')\n")
  204.  
  205.     outfile.write("    mygroup.copyalldata(info.subitem(0))\n    quarkpy.mapbtns.dropitemsnow(editor, [mygroup], 'draw map')\n\n")
  206.  
  207.     outfile.write("plugins.map1addonsmenu."+catagory+".items.append(quarkpy.qmenu.item('Import "+name+" map', Load_"+name+"_Map,'|This maps location is:\\n\\n"+objfile+"'))\n\n")
  208.  
  209.     outfile.write("# ------------ End Item Cutting ------------\n\n")
  210.  
  211.     outfile.write("#===========================================\n\n")
  212.  
  213.     outfile.write("# End Of File\n")
  214.  
  215.     outfile.close()
  216.  
  217. #        ********** Addons FUNCTION Ends Here **********
  218.  
  219. def AddItemClick(m):
  220.     def action(self):
  221.  
  222.         if self.src["catagory"] is None:
  223.             quarkx.msgbox("You have not selected a catagory, nothing done", MT_ERROR, MB_OK)
  224.             return
  225.         if self.src["program"] is None:
  226.             quarkx.msgbox("You have not entered a program, nothing done", MT_ERROR, MB_OK)
  227.             return
  228.         if self.src["mapfile"] is None:
  229.             quarkx.msgbox("You have not entered a mapfile, nothing done", MT_ERROR, MB_OK)
  230.             return
  231.         pass
  232.         catagory = self.src["catagory"]
  233.         program = self.src["program"]
  234.         words = program.split("\\")
  235.         cmdline = words [-1]
  236.         path_to_program = words [ 0 : -1 ]
  237.         currentdir = "\\".join(path_to_program)
  238.         words = cmdline.split(".")
  239.         name =  words [0]
  240.         name = name.replace(" ", "")
  241.         proglocate = program.replace("\\", "/")
  242.  
  243.         files = (quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  244.  
  245.         if len(files) != 0:
  246.             text = ""
  247.  
  248.             try:
  249.                 f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  250.             except (IOError):
  251.  
  252.  
  253. # *********** If first time used then it runs this script **********
  254.  
  255.                 CreateMenuItems(self)
  256.  
  257.                 quarkx.msgbox("The menu item has been added and stored\nin the newly created Addons Menu Edit file:\n"+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
  258.  
  259.                 return None
  260.  
  261. # ******** If map1AddonsMenuEdit.py file exists but no items ********
  262.  
  263.             NbrOfBoxes = 0
  264.  
  265.             while 1:
  266.                 line = f.readline()
  267.                 if line == '': # completely empty line means end-of-file
  268.                     break
  269.  
  270.                 words = line.split('\r\n')
  271.                 for word in words:
  272.  
  273.                     if word == "# ------------ Delete This Item ------------\n":
  274.                         NbrOfBoxes = NbrOfBoxes + 1
  275.  
  276.             if NbrOfBoxes == 0:
  277.                 f.close()
  278.                 CreateMenuItems(self)
  279.  
  280.                 quarkx.msgbox("The item has been added to the Addons Menu Edit file: "+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
  281.  
  282.                 return
  283.  
  284. # ********** If map1AddonsMenuEdit.py file already exists with items **********
  285.  
  286. # ********* This part sets parameters and  starts copying the old file data *******
  287.  
  288.             NewItem = ""
  289.             itemadded = 0
  290.             flag = 0
  291.             if catagory == "1":
  292.                 catagory = "ShapesMenu"
  293.             if catagory == "2":
  294.                 catagory = "TerrainMenu"
  295.             if catagory == "3":
  296.                 catagory = "OtherMenu"
  297.             mapfile = self.src["mapfile"]
  298.             objfile = mapfile.replace("\\", "/")
  299.  
  300.             f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  301.  
  302.             while 1:
  303.                 line = f.readline()
  304.                 if line == '': # completely empty line means end-of-file
  305.                     break
  306.  
  307.                 words = line.split('\r\n')
  308.                 for word in words:
  309.  
  310.                     if word == "plugins.map1addonsmenu." + catagory + ".items.append(qmenu.sep)\n":
  311.                         itemadded = 1
  312.                         flag = 1
  313.  
  314.                     if itemadded == 1:
  315.                         me = 1
  316.                     else:
  317.                         if catagory == "ShapesMenu":
  318.                             if word == "plugins.map1addonsmenu.TerrainMenu.items.append(qmenu.sep)\n":
  319.                                 holdword = word
  320.                                 NewItem = "ItemAdded"
  321.                                 itemadded = 1
  322.                                 flag = 1
  323.                                 word = "#===========================================\n"
  324.                             else:
  325.                                 if word == "plugins.map1addonsmenu.OtherMenu.items.append(qmenu.sep)\n":
  326.                                     holdword = word
  327.                                     NewItem = "ItemAdded"
  328.                                     itemadded = 1
  329.                                     flag = 1
  330.                                     word = "#===========================================\n"
  331.                     if itemadded == 1:
  332.                         me = 1
  333.                     else:
  334.                         if catagory == "TerrainMenu":
  335.                             if word == "plugins.map1addonsmenu.OtherMenu.items.append(qmenu.sep)\n":
  336.                                 holdword = word
  337.                                 NewItem = "ItemAdded"
  338.                                 itemadded = 1
  339.                                 flag = 1
  340.                                 word = "#===========================================\n"
  341.                         else:
  342.                             if catagory == "OtherMenu":
  343.                                 if word == "# End Of File\n":
  344.                                     holdword = word
  345.                                     NewItem = "ItemAdded"
  346.                                     itemadded = 1
  347.                                     flag = 1
  348.                                     word = "#===========================================\n"
  349.  
  350.  
  351.                     if flag == 1:
  352.                         if word == "#===========================================\n":
  353.  
  354. # ********* This part adds the new data then finishes copying the old file data *******
  355.  
  356.                             text = text + ("plugins.map1addonsmenu."+catagory+".items.append(qmenu.sep)\n\n")
  357.  
  358.                             text = text + ("# ------------ Delete This Item ------------\n\n")
  359.  
  360.                             text = text + ("# Menu Catagory: "+catagory+"\n")
  361.  
  362.                             text = text + ("# Menu Title: Run "+name+"\n\n")
  363.  
  364.                             text = text + ("def Run_"+name+"(self):\n    pass\n    cmdline = '"+cmdline+"'\n    currentdir = '"+currentdir+"'\n    quarkx.runprogram(cmdline, currentdir)\n\n")
  365.  
  366.                             text = text + ("plugins.map1addonsmenu."+catagory+".items.append(quarkpy.qmenu.item('Run "+name+"', Run_"+name+",'|This programs location is:\\n\\n"+proglocate+"'))\n\n")
  367.  
  368.                             text = text + ("# ------------ End Item Cutting ------------\n\n")
  369.  
  370.                             text = text + ("# ------------ Delete This Item ------------\n\n")
  371.  
  372.                             text = text + ("# Menu Catagory: "+catagory+"\n")
  373.  
  374.                             text = text + ("# Menu Title: Import "+name+" map\n\n")
  375.  
  376.                             text = text + ("def Load_"+name+"_Map(editor):\n    pass\n    editor = mapeditor()\n    info = quarkx.openfileobj('"+objfile+"')\n    mygroup = quarkx.newobj('group:g')\n")
  377.  
  378.                             text = text + ("    mygroup.copyalldata(info.subitem(0))\n    quarkpy.mapbtns.dropitemsnow(editor, [mygroup], 'draw map')\n\n")
  379.  
  380.                             text = text + ("plugins.map1addonsmenu."+catagory+".items.append(quarkpy.qmenu.item('Import "+name+" map', Load_"+name+"_Map,'|This maps location is:\\n\\n"+objfile+"'))\n\n")
  381.  
  382.                             text = text + ("# ------------ End Item Cutting ------------\n\n")
  383.  
  384.                             flag = 0
  385.                     if NewItem == "ItemAdded":
  386.                         text = text + ("#===========================================\n\n")
  387.                         word = holdword
  388.                         NewItem = ""
  389.  
  390.                     text = text + word
  391.  
  392.             f.close()
  393.             file = quarkx.newfileobj(files[0])
  394.             file["Data"] = text
  395.             file.savefile(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  396.             del file
  397.             quarkx.msgbox("The item has been added to the Addons Menu Edit file: "+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
  398.  
  399.  
  400.     editor=mapeditor()
  401.     if editor is None: return
  402.     AddonsDlg(quarkx.clickform,editor,action)
  403.  
  404. # ****************** END OF ADD TO MENU SECTION ******************
  405.  
  406.  
  407. # ****************** Remove Menu Items Function ******************
  408.  
  409. # ******************* Delete Menu Items Dialog ******************
  410.  
  411. class DeleteDlg(quarkpy.qmacro.dialogbox):
  412.  
  413.  
  414.     def BuildCheckboxesForDialog(self, array):
  415.  
  416. # creates the menu array data from the map1AddonsMenuEdit.py file
  417.  
  418. # *************************** start of array ********************
  419.  
  420.         cat = '0'
  421.         shapes = '0'
  422.         terrain = '0'
  423.         other = '0'
  424.         text = ''
  425.         shapestext = ''
  426.         terraintext = ''
  427.         othertext = ''
  428.  
  429.         try:
  430.             f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  431.  
  432.         except (IOError):
  433.             quarkx.msgbox("No custom items have been\nadded to the Category menus\n\n    Nothing To Do", MT_INFORMATION, MB_OK)
  434.             return None
  435.  
  436.         while 1:
  437.             line = f.readline()
  438.             if line == '': # completely empty line means end-of-file
  439.                 break
  440.             words = line.split('\n')
  441.             words = line.split(' ')
  442.             for word in words:
  443.                 if word == 'Catagory:':
  444.                     catagory = (line[2:+16])
  445.                     if cat == '0':
  446.                         cat = '1'
  447.                         menuname = (line[17:+62])
  448.                         if menuname == 'ShapesMenu\012':
  449.                             if shapes == '0':
  450.                                 shapestext = menuname
  451.                                 shapes = '1'
  452.                         if menuname == 'TerrainMenu\012':
  453.                             if terrain == '0':
  454.                                 terraintext = menuname
  455.                                 terrain = '1'
  456.                         if menuname == 'OtherMenu\012':
  457.                             if other == '0':
  458.                                 othertext = menuname
  459.                                 other = '1'
  460.                     else:
  461.                         menuname = (line[17:+62])
  462.                         if menuname == 'ShapesMenu\012':
  463.                             if shapes == '0':
  464.                                 shapestext = menuname
  465.                                 shapes = '1'
  466.                         if menuname == 'TerrainMenu\012':
  467.                             if terrain == '0':
  468.                                 terraintext = menuname
  469.                                 terrain = '1'
  470.                         if menuname == 'OtherMenu\012':
  471.                             if other == '0':
  472.                                 othertext = menuname
  473.                                 other = '1'
  474.  
  475.                 if word == 'Title:':
  476.                         itemname = (line[14:+62])
  477.                         if menuname == 'ShapesMenu\012':
  478.                             shapestext = shapestext + itemname
  479.                         if menuname == 'TerrainMenu\012':
  480.                             terraintext = terraintext + itemname
  481.                         if menuname == 'OtherMenu\012':
  482.                             othertext = othertext + itemname
  483.  
  484.         data = shapestext + terraintext + othertext
  485.         f.close()
  486.  
  487. # ************** MAKE DIALOG *******************
  488.  
  489.         contentstemplate = """
  490.         Contents:={Txt="<text>" Typ="S" Hint="Check to remove items below"} """
  491.  
  492.         septemplate = """sep: = { Typ="S" Txt="" }"""
  493.  
  494.         checkboxtemplate = """
  495.         cb<number>: =
  496.             { Typ="X" Cap="<caption>" Txt="<text>" } """
  497.  
  498.         dlgdef = """
  499.             {
  500.             Style="9"
  501.             Caption="Delete Checked Items from Menu"
  502.             <checkboxes>
  503.             sep: = { Typ="S" Txt="" }
  504.             close:py = {Txt="" }
  505.             cancel:py = {Txt="" }
  506.             } """
  507.  
  508.         Contents = ""
  509.         labelArray = ""
  510.         array = data
  511.         checkboxes_string = ""
  512.         num = 0
  513.         words = array.split('\n')
  514.  
  515.         for item in words:
  516.             if item == '': # completely empty line means end-of-file
  517.                 break
  518.  
  519.             if item == "ShapesMenu":
  520.                 labelArray = "Shapes Menu :"
  521.                 contents = contentstemplate.replace("<text>", labelArray)
  522.                 checkboxes_string = checkboxes_string + contents
  523.             else:
  524.  
  525.                 if item == "TerrainMenu":
  526.                     labelArray = "Terrain Menu :"
  527.                     contents = septemplate + contentstemplate.replace("<text>", labelArray)
  528.                     checkboxes_string = checkboxes_string + contents
  529.                 else:
  530.  
  531.                     if item == "OtherMenu":
  532.                         labelArray = "Other Menu :"
  533.                         contents = septemplate + contentstemplate.replace("<text>", labelArray)
  534.                         checkboxes_string = checkboxes_string + contents
  535.  
  536.                     else:
  537.                         num = num + 1
  538.                         my_caption = item
  539.                         my_text = ""
  540.                         checkbox_string = checkboxtemplate.replace("<number>", str(num))
  541.                         checkbox_string = checkbox_string.replace("<caption>", my_caption)
  542.                         checkbox_string = checkbox_string.replace("<text>", my_text)
  543.                         checkboxes_string = checkboxes_string + checkbox_string
  544.  
  545.         new_dlgdef = dlgdef.replace("<checkboxes>", checkboxes_string)
  546.  
  547.         return new_dlgdef
  548.  
  549.  
  550. # ********************** end of dialog definition ***********************
  551.  
  552.     #
  553.     # dialog layout
  554.     #
  555.  
  556.     endcolor = AQUA
  557.     size = (220,300)
  558.     dfsep = 0.05
  559.     flags = FWF_KEEPFOCUS
  560.  
  561.     #
  562.     # __init__ initialize the object
  563.     #
  564.  
  565.     def __init__( self, form, editor, action):
  566.  
  567.         self.dlgdef = self.BuildCheckboxesForDialog(self)
  568.  
  569.     #
  570.     # General initialization of some local values
  571.     #
  572.         self.editor = editor
  573.         src = quarkx.newobj(":")
  574.         self.src = src
  575.         self.action = action
  576.         self.form = form
  577.  
  578.     #
  579.     # Create the dialog form and the buttons
  580.     #
  581.         quarkpy.qmacro.dialogbox.__init__(self, form, src,
  582.         close = quarkpy.qtoolbar.button(
  583.             self.close,
  584.             "Remove the selected items\nfrom their Menu Catagories",
  585.             ico_editor, 3,
  586.             "Reload"),
  587.         cancel = quarkpy.qtoolbar.button(
  588.             self.cancel,
  589.             "Cancel & close window",
  590.             ico_editor, 0,
  591.             "Cancel"))
  592.  
  593.     def onclose(self, dlg):
  594.         if self.src is None:
  595.             qmacro.dialogbox.onclose(self, dlg)
  596.             return
  597.         quarkx.globalaccept()
  598.         line = self.BuildCheckboxesForDialog(self)
  599.         self.action(self)
  600.         qmacro.dialogbox.onclose(self, dlg)
  601.  
  602.     def cancel(self, dlg):
  603.         self.src = None 
  604.         qmacro.dialogbox.close(self, dlg)
  605.  
  606.  
  607. #     ********** Delete Dialog Setup Ends Here **********
  608.  
  609. # *************** Start of Click function ***************
  610.  
  611. def RemoveItemClick(m):
  612.  
  613. # ******** If map1AddonsMenuEdit.py file exists but no items ********
  614.  
  615.     try:
  616.         f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  617.  
  618.         NbrOfBoxes = 0
  619.  
  620.         while 1:
  621.             line = f.readline()
  622.             if line == '': # completely empty line means end-of-file
  623.                 break
  624.  
  625.             words = line.split('\r\n')
  626.             for word in words:
  627.  
  628.                 if word == "# ------------ Delete This Item ------------\n":
  629.                     NbrOfBoxes = NbrOfBoxes + 1
  630.         if NbrOfBoxes == 0:
  631.             f.close()
  632.  
  633.             quarkx.msgbox("No custom items exist\nin the Category menus\n\nNothing To Remove", MT_INFORMATION, MB_OK)
  634.  
  635.             return None
  636.     except (IOError):
  637.         me = 1
  638.  
  639. # ******** End of check. If there are items now it gos on ********
  640.  
  641.  
  642.     def action(self):
  643.  
  644. # files is the Data output file
  645.  
  646.         files = (quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  647.  
  648. #used just to get the looping to work
  649. # Checkbox layout text
  650.  
  651.         line = self.BuildCheckboxesForDialog(self)
  652.  
  653. # To get the number of check boxes there are
  654.  
  655.         totalboxes = line.count('cb') + 1
  656.  
  657. # This lets us setup the format needed later
  658. # to see if a check box is checked (returns 1)
  659. # to delete the menu item or unchecked (returns none)
  660. # to include it in the AddonsEditMenu file rewrite
  661.  
  662.         checkboxtemplate = """cb<number>"""
  663.  
  664. # Sets our checkbox number to 0
  665. # loops, creates the checkbox number
  666.  
  667.         loops = 0
  668.  
  669. # Sets up text file to write to and checkbox format to test
  670.  
  671.         text = ""
  672.         cbx = checkboxtemplate.replace("<number>", str(loops))
  673.         deleteflag = 0
  674.         deleteLF = 0
  675.  
  676. # Opens the data file and starts rewrite function
  677. # Data input file
  678.  
  679.         f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  680.         while 1:
  681.             file = f.readline()
  682.             if file == '': # completely empty line means end-of-file
  683.                 f.close()
  684.                 break
  685.             words = file.split('\r\n')
  686.             for word in words:
  687.                 if word == "# ------------ Delete This Item ------------\n":
  688.                     loops = loops + 1
  689.                     cbx = checkboxtemplate.replace("<number>", str(loops))
  690.  
  691. # If the box is checked, we skip it for the rewrite process
  692.  
  693.                     if self.src[cbx] == "1":
  694.                         deleteflag = 1
  695.  
  696.                 if deleteflag == 1:
  697.                     if word == "# ------------ End Item Cutting ------------\n":
  698.                         deleteLF = 1
  699.  
  700.                     if deleteLF == 1:
  701.                         if word == "\n":
  702.                             deleteLF = 0
  703.                             deleteflag = 0
  704.                     else:
  705.                         me = 1
  706.  
  707. # If it is not checked, we rewrite it to the new menu edit file
  708.  
  709.                 else:
  710.                     text = text + word
  711.  
  712.         file = quarkx.newfileobj(files[0])
  713.         file["Data"] = text
  714.         file.savefile(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  715.         del file
  716.  
  717.  
  718. # Reopens file 1st time to test and remove unwanted spacer lines
  719.  
  720.         text = ""
  721.         flag = 0
  722.         DulLines = ""
  723.         holdLFs = ""
  724.         SpacerWord = ""
  725.         f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  726.         while 1:
  727.             file = f.readline()
  728.             if file == '': # completely empty line means end-of-file
  729.                 f.close()
  730.                 break
  731.             words = file.split('\r\n')
  732.  
  733.             for word in words:
  734.                 if word == "#===========================================\n":
  735.                     if flag == 0:
  736.                         text = text + word + "\n"
  737.                         DulLines = word
  738.                         flag = 1
  739.                         break
  740.  
  741.                 if flag == 1:
  742.                     if word == "\n":
  743.                         break
  744.                     else:
  745.                         holdLFs = ""
  746.                         flag = 3
  747.  
  748.                 if flag == 2:
  749.                     if word == "\n":
  750.                         flag = 3
  751.                         break
  752.  
  753.                 if flag == 3:
  754.                     if word == "# ------------ Delete This Item ------------\n":
  755.                         text = text + SpacerWord + "\n" + word
  756.                         flag = 4
  757.                         break
  758.  
  759.                     if word == "#===========================================\n":
  760.                         text = text + word
  761.                         holdLFs = ""
  762.                         SpacerWord = ""
  763.                         flag = 2
  764.                         break
  765.  
  766.                     if word == "# End Of File\n":
  767.                         text = text + word
  768.                         flag = 5
  769.                         break
  770.  
  771.                     else:
  772.                         SpacerWord = word
  773.                         holdLFs = ""
  774.                         flag = 2
  775.                         break
  776.  
  777.                 if flag == 4:
  778.                     if SpacerWord == word:
  779.                         holdLFs = ""
  780.                         flag = 2
  781.                         break
  782.  
  783.                     if word == "#===========================================\n":
  784.                         text = text + word + "\n"
  785.                         SpacerWord = ""
  786.                         holdLFs = ""
  787.                         flag = 2
  788.                         break
  789.  
  790.                     else:
  791.                         text = text + word
  792.                         break
  793.  
  794.                 else:
  795.                     text = text + word
  796.  
  797.         file = quarkx.newfileobj(files[0])
  798.         file["Data"] = text
  799.         file.savefile(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  800.         del file
  801.  
  802.  
  803. # Reopens file 2nd time to test and remove unwanted double lines
  804.  
  805.         files = (quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  806.         text = ""
  807.         flag = 0
  808.         DulLines = "#===========================================\n"
  809.         f = open(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  810.         while 1:
  811.             file = f.readline()
  812.             if file == '': # completely empty line means end-of-file
  813.                 f.close()
  814.                 break
  815.             words = file.split('\r')
  816.  
  817.             for word in words:
  818.                 if flag == 0:
  819.                     if DulLines == word:
  820.                         flag = 1
  821.                         text = text + word
  822.                         break
  823.  
  824.                 if flag == 1:
  825.                     if "\n" == word:
  826.                         text = text + word
  827.                         flag = 2
  828.                         break
  829.                     else:
  830.                         text = text + word
  831.                         flag = 0
  832.                         break
  833.  
  834.                 if flag == 2:
  835.                     if DulLines == word:
  836.                         flag = 0
  837.                         break
  838.                     else:
  839.                         flag = 0
  840.                         text = text + word
  841.                         break
  842.                 else:
  843.                     text = text + word
  844.  
  845.         file = quarkx.newfileobj(files[0])
  846.         file["Data"] = text
  847.         file.savefile(quarkx.exepath + "plugins\map1AddonsMenuEdit.py")
  848.         del file
  849.  
  850. # ********* End of Remove Double Lines function *********
  851.  
  852.  
  853.         quarkx.msgbox("The checked menu items have been removed\nfrom the recreated Addons Menu Edit file:\n"+("\r\n" + quarkx.exepath + "plugins\map1AddonsMenuEdit.py")+"\n\nYou need to restart QuArK to undate the menu", MT_INFORMATION, MB_OK)
  854.  
  855.     editor=mapeditor()
  856.     if editor is None: return
  857.     DeleteDlg(quarkx.clickform,editor,action)
  858.  
  859. # **************** END OF REMOVE FROM MENU SECTION ****************
  860.  
  861.  
  862. # ********* This creates the Addons Amend menu items ***************
  863.  
  864. def ViewAmendMenu(editor):
  865.  
  866.     grouplist = filter(lambda o: o.type==':g', editor.layout.explorer.sellist)
  867.     onclick = quarkpy.mapbtns.groupview1click
  868.  
  869.     X0 = quarkpy.qmenu.item("Add menu item", AddItemClick, "|Add menu item:\n\nThis will add a 3rd party program to the menu.\n\nUsing the 'Add Item Dialog' window, select a category to place your menu items under and then find the program you want to add by using the 'select program' file browser '...' button to the right of the input box.\n\nYou can either leave the output/input default file at its current setting and point the programs output to it or use the 'File Browser' button ... to select another map file and location to use.\n\nOnce the program items are added, you will be given a notice as such and to restart QuArk to complete the process of adding the items to your menu.\n\nYou can add as many items to your menu as you like before restarting QuArk.\n\nEach program added will have two items (with the programs name) and a separation line to isolate them for easy recognition, as well as F1 popup windows to remind you where the program and import files are located on your hard drive.\n\nThe first item starts the program. Once you have exported its finished product to the default map file, then use the second item to import the map file into the QuArk editor. The entire product will be added to the map you are currently working on as a separate group item.\n\nAlthough the 'worldspawn' entity will NOT be imported, other entities can be and may require you to delete them, like another 'info_player_start' for example.\n\nBecause these ARE 3rd party programs, QuArK does not provide any documentation on their use and makes no warranty for them.|intro.mapeditor.menu.html#addonsmenu")
  870.  
  871.     X1 = quarkpy.qmenu.item("Remove menu items", RemoveItemClick, "|Remove menu items:\n\nUse this function to remove the desired custom menu items that have been added.|intro.mapeditor.menu.html#addonsmenu")
  872.  
  873.  
  874.     menulist = [X0, X1]
  875.     return menulist
  876.  
  877.  
  878. shortcuts = {}
  879.  
  880. # ************************************************************
  881. # ************************************************************
  882.  
  883. def ViewAmendMenu1click(m):
  884.     editor = mapeditor(SS_MAP)
  885.     if editor is None: return
  886.     m.items = ViewAmendMenu(editor)
  887.  
  888.  
  889. AmendMenuCmds = [quarkpy.qmenu.popup("&Add \ Delete menu items", [], ViewAmendMenu1click, "|Add \ Delete menu items:\n\nThese functions allow you to add and delete 3rd party programs to this menu, that save or export their output to a map file which can then be imported to the QuArK editor and used in the file you are editing.\n\nYou can use any .map file that the program outputs to, at any location, or a default map file as your input file.\n\nThe default import file should be created and saved to YourGame\\tmpQuArk\maps folder and named '1SaveImport.map' .\n\nIf this file is damaged or lost it can be recreated by simply making a basic map file in QuArk (with world_spawn ONLY) and saved with the default file name above.", "intro.mapeditor.menu.html#addonsmenu")]
  890.  
  891.  
  892. # ----------- REVISION HISTORY ------------
  893. #
  894. #$Log: map1addonsamendmenu.py,v $
  895. #Revision 1.2  2003/12/18 21:51:46  peter-b
  896. #Removed reliance on external string library from Python scripts (second try ;-)
  897. #
  898. #Revision 1.1  2003/07/04 20:01:16  cdunde
  899. #To add new Addons main menu item and sub-menus
  900. #
  901.